# create a new koji hub server system
# NOTE: should be used with --limit most of the time
# NOTE: most of these vars_path come from group_vars/koji-hub or from hostvars

- import_playbook: "/srv/web/infra/ansible/playbooks/include/virt-create.yml myhosts=koji-stg:koji"

# Once the instance exists, configure it.

- name: make koji_hub server system
  hosts: koji-stg:koji
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  pre_tasks:
    - import_tasks: "{{ tasks_path }}/osbs_certs.yml"
    - import_tasks: "{{ tasks_path }}/osbs_repos.yml"

  roles:
  - base
  - rkhunter
  - nagios_client
  - hosts
  - fas_client
  - builder_repo
  - collectd/base
  - apache
  - fedmsg/base
  - role: keytab/service
    service: kojira
    host: "koji{{env_suffix}}.fedoraproject.org"
  - role: keytab/service
    service: koji-gc
    owner_user: apache
    host: "koji{{env_suffix}}.fedoraproject.org"
  - koji_hub
  - role: keytab/service
    service: HTTP
    owner_user: apache
    host: "koji{{env_suffix}}.fedoraproject.org"
    when: "fedmsg_koji_instance == 'primary'"
  - role: keytab/service
    service: shadow
    owner_user: koji_shadow
    host: "koji{{env_suffix}}.fedoraproject.org"
    when: "fedmsg_koji_instance != 'primary'"
  - { role: nfs/server, when: env == "staging" }
  - { role: keepalived, when: env == "production" and inventory_hostname.startswith('koji') }
  - role: nfs/client
    mnt_dir: '/mnt/fedora_koji'
    nfs_src_dir: 'fedora_koji'
    when: env == 'production' and inventory_hostname.startswith('koji')
  - role: nfs/client
    mnt_dir: '/mnt/koji'
    nfs_src_dir: 'fedora_s390/data'
    when: env == 'production' and inventory_hostname.startswith('s390')
  - role: nfs/client
    mnt_dir: '/mnt/koji'
    nfs_src_dir: 'fedora_ppc/data'
    when: env == 'production' and inventory_hostname.startswith('ppc')
  - role: nfs/client
    mnt_dir: '/mnt/koji'
    nfs_src_dir: 'fedora_arm/data'
    when: env == 'production' and inventory_hostname.startswith('arm')
    # In staging, we mount fedora_koji as read only (see nfs_mount_opts)
  - role: nfs/client
    mnt_dir: '/mnt/fedora_koji_prod'
    nfs_src_dir: 'fedora_koji'
    when: env == 'staging' and inventory_hostname.startswith('koji')
  - sudo

  tasks:
  - name: create secondary volume dir for stg koji
    file: dest=/mnt/koji/vol state=directory owner=apache group=apache mode=0755
    tags: koji_hub
    when: env == 'staging'
  - name: create symlink for stg/prod secondary volume
    file: src=/mnt/fedora_koji_prod/koji dest=/mnt/koji/vol/prod state=link
    tags: koji_hub
    when: env == 'staging'
  - import_tasks: "{{ tasks_path }}/yumrepos.yml"
  - import_tasks: "{{ tasks_path }}/2fa_client.yml"
  - import_tasks: "{{ tasks_path }}/motd.yml"

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"


#- name: Start the kojid builder daemon, but only on staging.
#  # Really -- this should never be set for prod.
#  hosts: koji-stg:s390-koji01.qa.fedoraproject.org
#  user: root
#  gather_facts: True
#
#  # XXX - should these just be included in koji_builder and koji_hub roles?
#  tasks:
#  - name: make sure kojid is running
#    service: name=kojid state=started
#    tags:
#    - kojid
#  - name: make sure kojira is running
#    service: name=kojira state=started
#    tags:
#    - kojira
